<template>
  <!-- 放置一个图标 -->
  <div style="display:inline-block">
    <svg-icon
      :icon-class="icon ? 'exit-fullscreen' : 'fullscreen' "
      class="fullscreen"
      @click="Hclick"
    />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      icon: false
    }
  },
  created() {
    // ESC会改变当前的全屏状态
    // screenfull是插件，它自带事件监听 on
    // screenfull.isFullscreen ：插件自带的属性，表示当前是否处于全屏状态
    screenfull.on('change', () => {
      // 返回值 true || false
      console.log('当前是否是全屏', screenfull.isFullscreen)
      // 监听到变化自动修改这个变量,控制的图标
      this.icon = screenfull.isFullscreen
    })
  },
  methods: {
    Hclick() {
      // 切换显示的icon样式
      this.icon = !this.icon
      // 切换 全屏 非全屏
      screenfull.toggle()
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
